package ar.com.angrymachine.gameui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

public class Theme
{
	private Font smallBarFont;
	private Image uiImage;
	public String uiImageFile = "res/ui.png";
	private static final int UIBLOCK = 3;
	
	public Theme()
	{
		this(null);
	}
	public Theme(String uiImageFile)
	{
		smallBarFont = new Font("Verdana",Font.PLAIN, 11);
		if(uiImageFile != null)
		{
			this.uiImageFile = uiImageFile;
		}
	}
	
	public void fillUI(Graphics g, Rectangle area, boolean etched)
	{
		if(uiImage == null)
		{
			uiImage = GameCanvas.screen.loadImage(uiImageFile);
		}
		Utils.pushTranslation();
		Utils.translate(g, area.x, area.y);
		// paint fills
		// how many horizontal and vertical fills are needed?
		int hFills = area.width/UIBLOCK;
		int vFills = area.height/UIBLOCK;
		Utils.pushClipStack(g);
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(1,1,area.width-3,area.height-3);
		// paint sides
		g.clipRect(0,0,area.width,area.height-UIBLOCK);
		for(int y = 1 ; y != vFills; y++)
		{
			int py = y*UIBLOCK;
			drawUIItem(g, 0, 2, 0, py, etched); //left
			drawUIItem(g, 7, 2, area.width-UIBLOCK, py, etched); //right
		}
		Utils.popClipStack(g);
		Utils.pushClipStack(g);
		g.clipRect(0,0,area.width-UIBLOCK,area.height);
		for(int x = 1 ; x != hFills ; x++)
		{
			int px = x*UIBLOCK;
			drawUIItem(g, 3, 0, px, 0, etched); //upper
			drawUIItem(g, 3, 4, px, area.height-UIBLOCK, etched); //lower
		}
		Utils.popClipStack(g);
		// paint corners (clockwise)
		drawUIItem(g, 0, 0, 0, 0, etched);
		drawUIItem(g, 7, 0, area.width-UIBLOCK, 0, etched);
		drawUIItem(g, 7, 4, area.width-UIBLOCK, area.height-UIBLOCK, etched);
		drawUIItem(g, 0, 4, 0, area.height-UIBLOCK, etched);
		Utils.popTranslation(g);
	}
	
	private void drawUIItem(Graphics g, int srcX, int srcY, int dx, int dy, boolean etched)
	{
		int srcOffsetX = etched?10:0;
		g.drawImage(uiImage, dx, dy, dx+UIBLOCK, dy+UIBLOCK, srcX+srcOffsetX, srcY, srcX+UIBLOCK+srcOffsetX, srcY+UIBLOCK, Color.BLACK, null);
	}
	
    public Color buttonFillColor()
	{
    	return Color.DARK_GRAY;
    }
    
    public Color buttonBorderColor()
    {
    	return Color.WHITE;
    }
    
    public Font getDefaultSmallFont()
    {
        return smallBarFont;
    }

	public int getButtonRoundness()
	{
		return 10;
	}

	public Color getDefaultTextColor()
	{
		return Color.WHITE;
	}
	
	public int getDefaultBarWidth()
	{
		return 18;
	}
}
